<?php 

namespace app\controller\simManager;

use app\exception\ErrnoPlus;
use app\service\AdminAcountService;
use app\validate\LoginValidate;
use share\service\Factory4gManagerTableService;

class LoginController extends WebSimBossController{

    protected $beforeActionList = [
    ];


    public function initValidate(){
        $this->validate = new LoginValidate();
    }

    /**
     * 设置临时密码
     */
    public function login_action(){
        $data = $this->getAESDecodeData();
        $param = $this->check('webLogin',$data);
        $admin = self::adminAccount();
        $account = $param['account'];
        $password = $param['password'];
        $accountInfo = isset($admin[$account]) ? $admin[$account] : null;
        if(empty($accountInfo)){
            return self::fail("account or password error",ErrnoPlus::USER_NOT_EXISTS); 
        }
        if($accountInfo['pass'] !== $password){
            return self::fail("password or account error",ErrnoPlus::COMMON_ERROR); 
        }
        $token = self::authToken($accountInfo);
        return self::ok(['token' => $token]);
    }

    protected static function adminAccount(){
        return [
            'guofeng_admin' => [
                'pass' => 'd67841cb6c6dbcd',
                'factory' => Factory4gManagerTableService::FACTORY_ID_OF_GUOFENG,
            ],
            'yiyuan_admin' => [
                'pass' => 'e8fc59945898',
                'factory' => Factory4gManagerTableService::FACTORY_ID_OF_YIYUAN,
            ],
            'dongfang_admin' => [
                'pass' => '42bf61e38c76',
                'factory' => Factory4gManagerTableService::FACTORY_ID_OF_EAST_IOT,
            ],
            'miaoyue_admin' => [
                'pass' => 'c37cf8ee0e1a8b',
                'factory' => Factory4gManagerTableService::FACTORY_ID_OF_MUSMOON,
            ],
        ];
    }
  
   
}
